package com.waterdrop.wlsggk.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.waterdrop.wlsggk.mapper.TransferInventoryMapper;
import com.waterdrop.wlsggk.mapper.TransferResidueMapper;
import com.waterdrop.wlsggk.pojo.TransferInventory;
import com.waterdrop.wlsggk.pojo.TransferResidue;
import com.waterdrop.wlsggk.service.ITransferResidueService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 中转仓库剩余Service业务层处理
 *
 * @author Naruto
 * @date 2023-10-23
 */
@Service
public class TransferResidueServiceImpl implements ITransferResidueService {
    @Autowired
    private TransferResidueMapper transferResidueMapper;

    @Autowired
    private TransferInventoryMapper transferInventoryMapper;

    /**
     * 查询中转仓库剩余
     *
     * @param residueId 中转仓库剩余主键
     * @return 中转仓库剩余
     */
    @Override
    public TransferResidue selectTransferResidueByResidueId(Long residueId) {
        return transferResidueMapper.selectTransferResidueByResidueId(residueId);
    }

    /**
     * 查询中转仓库剩余列表
     *
     * @param transferResidue 中转仓库剩余
     * @return 中转仓库剩余
     */
    @Override
    public List<TransferResidue> selectTransferResidueList(TransferResidue transferResidue) {
        return transferResidueMapper.selectTransferResidueList(transferResidue);
    }

    /**
     * 新增中转仓库剩余
     * modify by Naruto
     * 【每次】统计完剩余，将剩余值更新为中转仓库最新数据
     * @param transferResidue 中转仓库剩余
     * @return 结果
     */
    @Override
    public int insertTransferResidue(TransferResidue transferResidue) {
        // 同步中转仓库中的数量
        TransferInventory transferInventory = new TransferInventory();
        BeanUtils.copyProperties(transferResidue, transferInventory);
        transferInventoryMapper.updateTransferInventory(transferInventory);
        // 记录本次剩余量
        return transferResidueMapper.insertTransferResidue(transferResidue);
    }

    /**
     * 修改中转仓库剩余
     *
     * @param transferResidue 中转仓库剩余
     * @return 结果
     */
    @Override
    public int updateTransferResidue(TransferResidue transferResidue) {
        transferResidue.setUpdateTime(DateUtils.getNowDate());
        return transferResidueMapper.updateTransferResidue(transferResidue);
    }

    /**
     * 批量删除中转仓库剩余
     *
     * @param residueIds 需要删除的中转仓库剩余主键
     * @return 结果
     */
    @Override
    public int deleteTransferResidueByResidueIds(Long[] residueIds) {
        return transferResidueMapper.deleteTransferResidueByResidueIds(residueIds);
    }

    /**
     * 删除中转仓库剩余信息
     *
     * @param residueId 中转仓库剩余主键
     * @return 结果
     */
    @Override
    public int deleteTransferResidueByResidueId(Long residueId) {
        return transferResidueMapper.deleteTransferResidueByResidueId(residueId);
    }
}
